<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>中国福利彩票</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">

<!--页面样式-->
<link rel="stylesheet" type="text/css" href="css/style.css" />

</head>
<body  style="width:10rem !important; margin:0 auto">
<script>
/*取设备宽度*/
	function rem(){
	var iWidth=document.documentElement.getBoundingClientRect().width;
	iWidth=iWidth>640?640:iWidth;
	document.getElementsByTagName("html")[0].style.fontSize=iWidth/10+"px";
	};
	rem();
	window.onorientationchange=window.onresize=rem      
</script>
<script src="js/jquery-1.7.2.min.js"></script>
<div class="Header">
<!--     	<div class="left H_logot"><a href="MemberCenter.html"><img src="images/logo.png"></a></div> -->
        <div class="left H_content text-center font28 cfffff">注册会员</div>
        <div class="right H_right text-right font24"><a href="Login.html">登录</a></div>
        <div class="clear"></div>
    </div>
    
    <div class="Forgetpwd">
    	<table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td colspan="2">
            	<div class="FPWD_li">
                	<dl>
                    	<dt><img src="images/Fimg1.png"></dt>
                        <dd><input type="text" class="DT_text1 font28 c666666 Weiruan" placeholder="手机号" id="phoneNum" maxlength="11"></dd>
                        <div class="clear"></div>
                    </dl>
                </div>
            </td>
          </tr>
          <tr>
            <td>
           	  <input type="text" class="DT_text2 font28 c666666 Weiruan marginT20" placeholder="验证码" id="smsCode" >
            </td>
            <td align="right">
            	<input type="button" id="smsCodeBtn" value="获取验证码" maxlength="8" class="FPWD_yan font28 cfffff Weiruan marginT20" onclick="getVerificationCode()">
            </td>
          </tr>
          <tr>
            <td colspan="2">
            	<div class="FPWD_li">
                	<dl>
                    	<dt><img src="images/Fimg2.png"></dt>
                        <dd><input type="password" class="DT_text1 font28 c666666 Weiruan" placeholder="密码" id="password"></dd>
                        <div class="clear"></div>
                    </dl>
                </div>
            </td>
          </tr>
          <tr>
            <td colspan="2">
            	<div class="cee4141 font18 R_ti marginT15">不小于8位，至少包含小写字母、大写字母、数字及字符中的两项。</div>
            </td>
          </tr>
          <tr style="display: none;">
            <td colspan="2">
            	<div class="RG_box font24 c666666 marginT30"><input name="agreement" type="checkbox" value="" checked id="agreement">已阅读并同意<a href="#">《彩民协议》</a></div>
            </td>
          </tr>
          <tr>
            <td colspan="2">
            	<input type="submit" value="注 册" class="FPWD_but font32 cfffff Weiruan marginT80"  onclick="nextStep()" />
            </td>
          </tr>
        </table>
    </div>
    	
<!-- 弹出alert -->	
	<div class="falert" style="display: none;" id="warnInfoDiv">
		<div class="falert_t font30"><span style="margin-left:0.15rem">提示</span></div>
		<div class="falert_b"><span id="warnInfo"></span><img class="dianji_gb" style="position:absolute;right:0.1rem;top:0.15rem;cursor:pointer;" width="45rem" src="images/Fimg8.png" onclick="closeWarnInfoDiv('warnInfoDiv')"/></div>
	</div>
<!-- 弹出alert -->
</body>
<script type="text/javascript">
var channelId="";
    /*弹框JS内容*/
    jQuery(document).ready(function($){
    	channelId = getCookie("channelId");
    });
   //获得“短信验证码”
    function getVerificationCode() {
	   //验证手机号格式
    	if(!validatePhoneNum('phoneNum')){
    		return;
    	}
	  var para = {
			  mobile:$('#phoneNum').val(),
			  type:1
	        };
	$.ajax({
		url : "../../api/accountSystem/verification/msgcode",
		async:false,
		type : "POST",
		herder:{
			'Accept':'application/json',
			'Content-Type':'application/json'
		},
		dataType:"json",
		contentType:"application/json",
		data:JSON.stringify(para),
		error:function(XMLHttpRequest, textStatus, errorThrown){
			alert(errorThrown);
		},
		success: function(data, textStatus){
			if(data.success==true){
				messageCodeTime('smsCodeBtn');
			}else{
				alert(data.description);
			}
		}		
	});
}   
   
      //点击“下一步”执行  
function nextStep() {
	 //验证是否勾选协议
	if(!validateAgreement('agreement')){
		return;
	}
	 //验证手机号格式
	if(!validatePhoneNum('phoneNum')){
		return;
	}
	 //验证手机验证码格式
	if(!validatesmsCode('smsCode')){
		return;
	}
	//验证密码
	if(!validateRegistePwd('password')){
		return;
	}
  var para = {
		  	mobile:$('#phoneNum').val(),
			password:sha256_digest($('#password').val()),
			smsCode:$('#smsCode').val(),
			channelId:channelId
        };
	
	$.ajax({
		url : "../../api/accountSystem/register",
		async:false,
		type : "POST",
		herder:{
			'Accept':'application/json',
			'Content-Type':'application/json'
		},
		dataType:"json",
		contentType:"application/json",
		data: JSON.stringify(para),
		error:function(XMLHttpRequest, textStatus, errorThrown){
			alert(errorThrown);
		},
		success: function(data, textStatus){
			if(data.success == true){
				login();
			}else{
				alert(data.description);
				return;
			}
		}		
	});
}   

      //注册成功调用login登录获得accountId和token
      function login(){
    	  var para = {
    			  	id:$('#phoneNum').val(),
    				password:sha256_digest($('#password').val()),
    				channelId:"1234567890"
    	        };
    		
    		$.ajax({
    			url : "../../api/accountSystem/login",
    			async:false,
    			type : "POST",
    			herder:{
    				'Accept':'application/json',
    				'Content-Type':'application/json'
    			},
    			dataType:"json",
    			contentType:"application/json",
    			data: JSON.stringify(para),
    			error:function(XMLHttpRequest, textStatus, errorThrown){
    				alert(errorThrown);
    			},
    			success: function(data, textStatus){
    				if(data.success == true){
    					if(data.status=="1000"){
    						setCookie('accountId',data.accountId,0);
    						setCookie('token',data.token,0);
    						window.location.href='Register1.html?password='+sha256_digest($('#password').val())+'';
    					}
    				}else{
    					window.location.assign(encodeURI('LoginDown.html?description='+data.description+''));
     					return;
    				}
    			}		
    		});
      }
</script>
<script src="js/SHA256.js"></script>
<script src="js/jsCallCookies.js"></script>
<script src="js/validation.js"></script>
<script src="js/countDown.js"></script>
<script src="js/common.js"></script>
</html>
